<%@ page language="java" contentType="text/html; charset=utf-8 " import="java.util.Date,java.text.*,service.community.*,domain.Room,domain.Community,domain.User,java.util.ArrayList"
    pageEncoding="utf-8"%>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <base href="<%=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/" %>"/>
    <meta charset="utf-8" />
    	<title></title>
    	</head>
    	<script src="js/mootools.js" type="text/javascript"></script>
        	<script type="text/javascript" src="js/jquery.min.js"></script>
        	<script type="text/javascript" src="js/jquery.imgbox.pack.js"></script>
        <script type="text/javascript">
            var xmlHttp;
             function createXMLHttp(){
                 if(window.XMLHttpRequest){
                    xmlHttp=new XMLHttpRequest();
                  }
                  else{
                    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                  }
             }
             function SateYes(e){
                  createXMLHttp();
                  xmlHttp.onreadystatechange=checkSateYes;
                  xmlHttp.open("post","RoomStateYes?Room_id="+e);
                  xmlHttp.send(null);
             }
             function checkSateYes(){
                  if(xmlHttp.readyState==4){
                    	if(xmlHttp.status==200){
                    		if(xmlHttp.responseText!=""&&xmlHttp.responseText!=null){
                    			alert("操作成功");
                    			location.reload();
                    		}
                    		else{
                    	        alert("操作失败");
                    	    }
                    	}
                   }
             }
             function SateNo(e){
                  createXMLHttp();
                  xmlHttp.onreadystatechange=checkSateYes;
                  xmlHttp.open("post","RoomStateNo?Room_id="+e);
                  xmlHttp.send(null);
             }
             function checkSateNo(){
                  if(xmlHttp.readyState==4){
                    	if(xmlHttp.status==200){
                    		if(xmlHttp.responseText!=""&&xmlHttp.responseText!=null){
                    			alert("操作成功");
                    			location.reload();
                    		}
                    		else{
                    	        alert("操作失败");
                    	    }
                    	}
                   }
             }
        	$(document).ready(function() {


        		$(".example2-1").imgbox({
        			'speedIn'		: 0,
        			'speedOut'		: 0,
        			'alignment'		: 'center',
        			'overlayShow'	: true,
        			'allowMultiple'	: false
        		});
        	});
        	</script>
    	<style type="text/css">
    		body{
    		color: #555;
    		background-color: rgba(0, 0, 0, 0.08);
    		font-size: 80%;
    			}
    		.navigation{
    			position: absolute;
    			height: 100%;
    			width: 20%;
    			top: 0;
    			left: 0;
    			box-shadow: rgba(0, 0, 0, 0.08) 0px 1px 4px 0px;
    			background: white;
    		}
    		.top{
    			position: absolute;
    			top: 0;
    			left: 21%;
    			height: 10%;
    			width: 78%;
    			box-shadow: rgba(0, 0, 0, 0.08) 0px 1px 4px 0px;
    			background: white;
    		}
    		.main{
    			position: absolute;
    			top: 12%;
    			left: 21%;
    			width: 78%;
    			height: 86%;
    			box-shadow: rgba(0, 0, 0, 0.08) 0px 1px 4px 0px;
    			background: white;
    		}
    		.logo{
    			margin: auto;
    			margin-top: 10%;
    			background: url(img/logo.png);
    			width: 60%;
    			margin-bottom:10% ;
    		}
    		.click_box{
    			text-align: center;
    			border-top: black solid 1px;
    			border-bottom: black solid 1px ;
    			background: #199ED8;
    			color: white;
    			padding: 3%;
    			font-size: 160%;
    		}
    		.unclick_box{
    			text-align: center;
    			border-top: black solid 1px;
    			border-bottom: black solid 1px ;
    			padding: 3%;
    			font-size: 160%;
    		}
    		.unclick_box:hover{
    			background: #199ED8;
    			color: white;
    		}
    		.out_login:hover{
    			color: #199ED8;
    		}
    		button{
            		margin:10px;
            		background: #199ED8;
            		font-size: 100%;
            		color: white;
            		width: 100px;
            		height: 30px;
            		border: 0px;
            		border-radius: 5px;
            	}
            	table{
            		position: relative;
            		top: 0;

            		min-height: 25px;
            		line-height: 25px;
            		text-align: center;
            		border-collapse: collapse;
            		top: 0%;
            		left: 5%;
            		width: 90%;
            		height: 75%;
            	}
            	td{
            		height: 6%;
            	}
            	th{
            		background: #199ED8;
            		color: white;
            	}
            	table tr:nth-child(odd){
            		background: #F2F2F2;
            	}
            	#shadow{
            		background: #000;
            		filter: alpha(opacity=50); /* IE的透明度 */
            		opacity: 0.9; /* 透明度 */
            		display: none;
            		position: fixed;
            		top: 0px;
            		left: 0px;
            		width: 100%;
            		height: 100%;
            		z-index: 100; /* 此处的图层要大于页面 */
            		display: none;
            	}
            	.box{
            		border: 1px solid black;
            		width: 30%;
            		height: 40%;
            		position: fixed;
            		top: 30%;
            		left: 35%;
            		opacity: 1;
            		margin: 0 auto;
            		text-align: center;
            		background: white;
            		border-radius: 5px;
            		z-index: 101;
            		box-shadow: rgba(0, 0, 0, 0.08) 0px 1px 4px 0px;
            	}
            	.title{
            		width: 100%;
            		background: #F2F2F2;
            		height: 15%;
            		border-top-left-radius: 5px;
            		border-top-right-radius: 5px;
            		box-shadow: rgba(0, 0, 0, 0.08) 0px 1px 4px 0px;
            		border-bottom: 0.5px antiquewhite solid;
            	}
            	input{
            		border: 1px solid #ccc;
            		padding: 7px 0px;
            		border-radius: 3px;
            		padding-left:5px;
            		-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
            		box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
            		-webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
            		-o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
            		transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s
            	}
            	input:focus{
            		border-color: #66afe9;
            		outline: 0;
            		-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6);
            		box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)
            	}
            	.imgbox-img{
            	    position:fixed;
            	    top:10%;
            	    left:20%

            	}
    	</style>
    	<%
                    	User user=new User();
                    	if(session.getAttribute("adminloginflag")==null){
                    	%>
                    	<script type="text/javascript">
                    	    window.location.href="admin/login.jsp";
                    	</script>
                        <% }else{
                        user=(User)session.getAttribute("adminloginflag");
                        if(user.getRoom_power()==0){
                        %>
                        <script type="text/javascript">
                     	    window.location.href="admin/error/error404.jsp";
                     	</script><% }%>
    	<body onload="messageLoad()">
    		<div class="navigation">
    			<center><img src="image/logo.png" class="logo"  /></center>
    			<% if(user.getUsername().equals("admin")){ %><div class="unclick_box" onclick="userManage()">用户配置</div> <% } %>
    			<% if(user.getCommunity_power()==1 ){%><div class="unclick_box" onclick="Community()">社区配置</div> <% } %>
    			<% if(user.getRoom_power()==1 ){%><div class="click_box" onclick="Room()">住房审核</div> <% } %>
    			<% if(user.getView_power()!=null&&!user.getView_power().equals("null") ){%><div class="unclick_box" onclick="info()">人员信息</div> <% } %>
    		</div>
    		<div class="top">
    			<div style="float: left;margin:2%;font-size: 160%;"><%=new SimpleDateFormat("yyyy-MM-dd E").format(new Date())  %></div>
    			<div style="float: right;margin:2%;font-size: 160%;">
    				<span> <img src="image/u954.svg"/></span>
    				<span style="margin-right: 20px;"><%=user.getUsername() %></span>
    				<span class="out_login" onclick="AdminOutlogin()">退出</span>
    			</div>
    		</div>
    		<div class="main">
            <div style="float: right;margin-right: 5%;margin-top: 3%;">
			<form method="post" action="RoomQuery" >
			<select id="community_id" name="community_id" style="width:100px;height:30px">
            					    <option value="0">全部</option>
            						<%  CommunityService communityService =new CommunityServiceImpl() ;
                                    								    ArrayList<Community> li = communityService.queryCommunity(user.getView_power());
                                    								    for(int j=0;j<li.size();j++){
                                    								    if(request.getAttribute("community_id")!=null){
                                    								        int num = Integer.parseInt(request.getAttribute("community_id").toString());
                                    								        if(num==li.get(j).getCommunity_id()){
                                    								%>
                                    <option selected="selected" value="<%=li.get(j).getCommunity_id() %>" ><%=li.get(j).getCommunity_name() %></option><%}else{ %>
                                    <option value="<%=li.get(j).getCommunity_id() %>" ><%=li.get(j).getCommunity_name() %></option> <% }}else{ %>
                                    <option value="<%=li.get(j).getCommunity_id() %>" ><%=li.get(j).getCommunity_name() %></option> <% }}%>
            						</select>
            <% if(request.getAttribute("query")!=null){ %>
            <input type="text" name="query" id="query" placeholder="查询关键字" value="<%=request.getAttribute("query") %>" /><% }else{ %>
			<input type="text" name="query" id="query" placeholder="查询关键字" /><% } %>
			<button type="submit">查询</button>
			</form>
		    </div>
		<table border="1">
			<tr>
			<th width="15%">门牌号</th>
			<th width="10%">拥有者</th>
			<th width="15%">所属社区</th>
			<th width="15%">手机</th>
			<th width="15%">登录名</th>
			<th width="10%">房产照片</th>
			<th width="10%">状态</th>
			<th width="10%">操作</th>

			</tr>
			<% for(int i=0;i<15;i++){ %>
			<tr>
			<% ArrayList<Room> list=(ArrayList)request.getAttribute("list");
			   if(i<list.size()){
			%>
			<td><%=list.get(i).getHousernum() %></td>
			<td><%=list.get(i).getOwnername() %></td>
			<td><%=list.get(i).getCommunity_name() %></td>
			<td><%=list.get(i).getPhone() %></td>
			<td><%=list.get(i).getUsername() %></td>
			<td><a class="example2-1" title="" href="<%=list.get(i).getHousecard_img() %>"><img src="<%=list.get(i).getHousecard_img() %>" height="3%" /></a></td>
			<td><% if(list.get(i).getState()==0){ %><span style="color:#555555">待审核</span><% }else if(list.get(i).getState()==1){ %>
			<span style="color:green;">已审核</span><% }else if(list.get(i).getState()==2){ %><span style="color:red;">未通过</span><% }%>
			</td>
			<td style="font-size:80%;"><% if(user.getVerify_power()==1){ %>
				<a  onclick="SateYes(<%=list.get(i).getRoom_id() %>)" >[通过]</a>
				<a  onclick="SateNo(<%=list.get(i).getRoom_id() %>)">[拒绝]</a><% }else{ %>无审核权限<% }%>
			</td>
			</tr><%} else{%>
			<td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><%}}%>
		</table>
		<% if(request.getAttribute("query")==null &&request.getAttribute("community_id")==null){ %>
		<div style="float: right;margin-right: 5%;margin-top: 1%;">
			<c:choose>
						<c:when test="${page.hasPrePage}">
							<a href="RoomInfo?method=list&currentPage=1">首页</a> |
					<a href="RoomInfo?method=list&currentPage=${page.currentPage -1 }">上一页</a>
						</c:when>
						<c:otherwise>

						</c:otherwise>
					</c:choose>
				   当前为第${page.currentPage}页,共${page.totalPage}页
			<c:choose>
						<c:when test="${page.hasNextPage}">
							<a href="RoomInfo?method=list&currentPage=${page.currentPage + 1 }">下一页</a> |
					<a href="RoomInfo?method=list&currentPage=${page.totalPage }">尾页</a>
						</c:when>
						<c:otherwise>

						</c:otherwise>
					</c:choose>
		</div>
			<% }if(request.getAttribute("query")!=null||request.getAttribute("community_id")!=null){ %>
			<div style="float: right;margin-right: 5%;margin-top: 1%;">
            			<c:choose>
            						<c:when test="${page.hasPrePage}">
            							<a href="RoomQuery?method=list&currentPage=1&query=<%=request.getAttribute("query") %>&community_id=<%=request.getAttribute("community_id") %>">首页</a> |
            					<a href="RoomQuery?method=list&currentPage=${page.currentPage -1 }&query=<%=request.getAttribute("query") %>&community_id=<%=request.getAttribute("community_id") %>">上一页</a>
            						</c:when>
            						<c:otherwise>

            						</c:otherwise>
            					</c:choose>
            				   当前为第${page.currentPage}页,共${page.totalPage}页
            			<c:choose>
            						<c:when test="${page.hasNextPage}">
            							<a href="RoomQuery?method=list&currentPage=${page.currentPage + 1 }&query=<%=request.getAttribute("query") %>&community_id=<%=request.getAttribute("community_id") %>">下一页</a> |
            					<a href="RoomQuery?method=list&currentPage=${page.totalPage }&query=<%=request.getAttribute("query") %>&community_id=<%=request.getAttribute("community_id") %>">尾页</a>
            						</c:when>
            						<c:otherwise>

            						</c:otherwise>
            					</c:choose>
            		</div><% } %>
    		</div>
    	</body>
    	<% } %>
    	<script type="text/javascript">
        	    function AdminOutlogin(){
        	    	window.location.href="AdminOutLogin";
        	    }
        	    function userManage(){
                    window.location.href="UserInfo";
                }
                function Community(){
                    window.location.href="CommunityInfo";
                 }
                function Room(){
                    window.location.href="RoomInfo";
                 }
                function info(){
                    window.location.href="Info";
                 }
        	</script>
    </html>